package com.ruoyi.paipan.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.paipan.common.Zwinfo;
import com.ruoyi.paipan.dto.ZWNZRequestDto;
import com.ruoyi.paipan.service.ZWNZService;
import com.ruoyi.paipan.utils.ToolUtil;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class ZWNZServiceImpl implements ZWNZService {
    @Override
    public LinkedHashMap<String,Object> getInfo(ZWNZRequestDto requestDto) {
        String bzg = requestDto.getBz();
        List<String> bz = Arrays.asList(ToolUtil.cn_substr(bzg, 0, 1), ToolUtil.cn_substr(bzg, 1, 1), ToolUtil.cn_substr(bzg, 2, 1), ToolUtil.cn_substr(bzg, 3, 1), ToolUtil.cn_substr(bzg, 4, 1), ToolUtil.cn_substr(bzg, 5, 1), ToolUtil.cn_substr(bzg, 6, 1), ToolUtil.cn_substr(bzg, 7, 1));
        List<String> tiangan = Arrays.asList("癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬");
        List<String> dizhi = Arrays.asList("亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌");
        List<String> sizhu = Arrays.asList(bz.get(0), bz.get(1), wz(tiangan, bz.get(0)), wz(dizhi, bz.get(1)), bz.get(2), bz.get(3), wz(tiangan, bz.get(2)), wz(dizhi, bz.get(3)), bz.get(4), bz.get(5), wz(tiangan, bz.get(4)), wz(dizhi, bz.get(5)), bz.get(6), bz.get(7), wz(tiangan, bz.get(6)), wz(dizhi, bz.get(7)));
        int sex = requestDto.getUsex();
        String gl_birthday = requestDto.getGl_birthday();
        int runfen = requestDto.getRunfen();
        int csmode = requestDto.getCsmode();
        LinkedHashMap<String,Object>  config = new LinkedHashMap<String,Object>(){{
            put("date" ,gl_birthday);
            put("sex" ,sex);
            put("runfen" ,runfen);
            put("csmode" ,csmode);
            put("sizhu" ,sizhu);
        }};
        Zwinfo info = new Zwinfo(config);
        LinkedHashMap<String,Object> zw = info.get_info();
        return zw;
    }

    private String wz(List<String> array, String find)
    {
        return String.valueOf(array.indexOf(find));
    }
}
